#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
Simplified BSD License (BSD)
Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this 
      list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
      this list of conditions and the following disclaimer in the documentation 
      and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

#region Record of Change
//             							CHANGE HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | DEVELOPER  | DESCRIPTION                                              |
// -------------------------------------------------------------------------------------
// | 11-Nov-09 | LamNPT      | First creation.                                          |
// -------------------------------------------------------------------------------------
//
#endregion

#region Record of Audit
//             							REVIEW HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | REVIEWER   | NOTES                                                    |
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//
#endregion

#region Using directives
using System;

using Thn;
using Thn.Drawing.Painters;
using System.Drawing;
using System.Drawing.Drawing2D;
using Thn.Drawing;
#endregion

namespace Thn.Interface.Vcl.Themes.BlueSea
{
    /// <summary>
    /// A base class inherit from <see cref="GlossPainterBase"/> custom
    /// for paint the vertical scroll control.
    /// </summary>
#if DEBUG 
    public
#else
    internal
#endif 
    abstract class VertialScrollGlossPainterBase : GlossPainterBase
    {
        #region Paint Rectangle
        /// <summary>
        /// Paint a rectangle with
        /// </summary>
        /// <param name="canvas">The canvas to paint to.</param>
        /// <param name="r">The region where to paint in.</param>
        /// <param name="includeBorder">Whether a border should be painted.</param>
        /// <param name="includeFill">Whether inner filling should be painted.</param>
        public override void PaintRectangle(Graphics canvas, Rectangle r, bool includeBorder, bool includeFill) 
        {
            #region Paint fillings

            if (includeFill)
            {
                //calculate gradient regions
                Rectangle r1 = new Rectangle(r.Left, r.Top, (int)(r.Width * mRatio), r.Height);
                Rectangle r2 = new Rectangle(r1.Right, r1.Top, r.Width - r1.Width, r.Height);

                //prepare brushes
                LinearGradientBrush b1 = new LinearGradientBrush(r1, mC1, mC2, 90f);
                LinearGradientBrush b2 = new LinearGradientBrush(r2, mC3, mC4, 90f);

                //paint
                canvas.FillRectangle(b1, r1);
                canvas.FillRectangle(b2, r2);

                //clean up
                b1.Dispose();
                b2.Dispose();
            }
            #region Defensive tracing
            else
            {
                //no need to paint
            }
            #endregion

            #endregion

            #region Paint border

            if (includeBorder)
            {
                Pen p = new Pen(mBorderColor);
                canvas.DrawRectangle(p, r);
                p.Dispose();
            }
            #region Defensive tracing
            else
            {
                //no need to paint
            }
            #endregion

            #endregion
        }
        #endregion

        #region Paint Rounded Rectangle
        /// <summary>
        /// Paint a rectangle with
        /// </summary>
        /// <param name="canvas">The canvas to paint to.</param>
        /// <param name="r">The region where to paint in.</param>
        /// <param name="includeBorder">Whether a border should be painted.</param>
        /// <param name="includeFill">Whether inner filling should be painted.</param>
        /// <param name="radius">Radius of corners.</param>
        public override void PaintRoundedRectangle(Graphics canvas, Rectangle r, bool includeBorder, bool includeFill, int radius) 
        {
            #region Calculate path
            GraphicsPath path = GraphicUtils.MakeRoundedRectangle(r, true, true, true, true, radius);
            #endregion

            #region Paint fillings

            if (includeFill)
            {
                //calculate gradient regions
                Rectangle r1 = new Rectangle(r.Left, r.Top, (int)(r.Width * mRatio), r.Height);
                Rectangle r2 = new Rectangle(r1.Right, r1.Top, r.Width - r1.Width, r.Height);

                //prepare brushes
                LinearGradientBrush b1 = new LinearGradientBrush(r1, mC1, mC2, 0f);
                LinearGradientBrush b2 = new LinearGradientBrush(r2, mC3, mC4, 0f);

                //paint            
                GraphicsState state = canvas.Save();
                canvas.SetClip(path);
                canvas.FillRectangle(b1, r1);
                canvas.FillRectangle(b2, r2);
                canvas.Restore(state);

                //clean up
                b1.Dispose();
                b2.Dispose();
            }
            #region Defensive tracing
            else
            {
                //no neeed to paint
            }
            #endregion

            #endregion

            #region Paint border

            if (includeBorder)
            {
                Pen p = new Pen(mBorderColor);
                canvas.DrawPath(p, path);
                p.Dispose();
            }
            #region Defensive tracing
            else
            {
                //no need to paint
            }
            #endregion

            #endregion

            path.Dispose();
        }
        #endregion
        
        #region Constructors
        /// <summary>
        /// Default constructor.
        /// </summary>
        public VertialScrollGlossPainterBase() 
        { }
        #endregion
    }
}